package acm.蓝桥12;


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static int n,m,k;
    static int[][] map;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        k=sc.nextInt();
        map=new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                map[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs(i,j,0,0);
            }
        }
        System.out.println(set.size());
    }
    static Set<Integer> set=new HashSet<>();
    static int[][] dirs={{0,1},{0,-1},{1,0},{-1,0}};
    public static void dfs(int x,int y,int deep,int path){
        if (deep>k){
            set.add(path);
            return;
        }
        int cur = path * 10 + map[x][y];
        for (int[] dir : dirs) {
            int x1=x+dir[0];
            int y1=y+dir[1];
            if (x1>=0&&x1<n&&y1>=0&&y1<m){
                dfs(x1,y1,deep+1, cur);
            }
        }
    }
}
